//初始化加载折线图和表格
$(document).ready(function () {
	siteKey = $("#siteKey").val();
	type = $("#hdtype").val();
	if(siteKey=="" || type ==""){
		var str = "<div class='em100 whitediv' id='zhanwushuju'><div class='em25'></div><div class='backyellow'>&nbsp;&nbsp;暂无数据！请选择场所</div></div>"
		$("#myForm .widthall .chartdiv").children("div[id!='zhanwushuju']").hide();
		$("#myForm .widthall .xiangxidiv").children("div[id!='zhanwushuju']").hide();
		$("#myForm .widthall .chartdiv").html(str);
		$("#myForm .widthall .xiangxidiv").html(str);
	}else{
		getspan('day_7');
	}
})

//时间段时间控件
$( function () {
	var endDate=new Date();//当前时间
	endDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate();
	var startDate=(new Date());
	startDate.setDate(startDate.getDate()-30);//前一个月时间
	startDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate();
	siteKey = $("siteKey").val();
 	if(siteKey!=""){
	    var dateObj = {
	        theme: 'ta', // 日期选择器TA主题
	        autoCommit: true, //自动提交，完成日期初始化，以及图表的展示拉取
	        isTodayValid: true,
	        startDate: startDate,
	        endDate: endDate,
	        needCompare: true,
	        startCompareDate: '',
	        endCompareDate: '',
	        singleCompare: false,
	        defaultText: ' 至 ',
	        autoSubmit: false,
	        shortOpr: false,
	        target: 'datePicker',
	        calendars: 2,
	        inputTrigger: 'input_trigger',
	        compareCheckboxId: false,
	        success: function (obj) {
	            if (($("#txtspan").val().split("_"))[1] == "0" || $("#needCompare").val() == "1")//处于如期选择框时
	            {
	                loadChart($("#hdtype").val());
	            }
	        }
	    };
	    new pickerDateRange("date", dateObj)
 	}
})


//加载折线图表取XY轴
function  getXY(result) {
	var xsisRe="";
	var dataRe="";
	var dataRe1="";
		for(var i=0;i<result.length;i++){
			xsisRe=xsisRe + result[i].datatime+",";
			indexNamefiled = "newCustomerNum";
			dataRe = dataRe+((getObjectVlue(result[i],indexNamefiled))==null?0:(getObjectVlue(result[i],indexNamefiled)))+",";
			indexNamefiled1 = "oldCustomer";
			dataRe1 = dataRe1+((getObjectVlue(result[i],indexNamefiled1))==null?0:(getObjectVlue(result[i],indexNamefiled1)))+",";
		}
	xsisRe=xsisRe.substring(0,xsisRe.length-1);
	dataRe=dataRe.substring(0,dataRe.length-1);
	dataRe1=dataRe1.substring(0,dataRe1.length-1);
	var result =new Array();
	result.push(xsisRe);
	result.push(dataRe);
	result.push(dataRe1);
	return result
}

//加载折线图表
 function loadChart(type) {
	 showLoading();
     var data = [];
     var xsis = [];
     var from = $('#startDate').val();
     var to = $('#endDate').val();
     var siteId= $("#siteKey").val();
     var tubiao = "tubiao1";
     var span = $("#txtspan").val();
     shijianCss(span);
     var myChart = echarts.init(document.getElementById(tubiao));
   	$.ajax( {
   		type : "GET",
   		contentType:"application/json",
   		dataType : 'json',
   		url: "getSquareKequnData",
   		data: { from: from, to: to,span: span, siteId: siteId },
   		async: true,
   		success : function(ret) {
   			var width = $("#tubiao1").width();
			var height = $("#tubiao1").height();
			var titleOffens = width*7.6/100;
			var dataZoomY = height*(1-19/100);
			var toolboxX = width*80/100;
			var legendY = height*4/100;
			var toolboxY = height*4/100;
			//获取当前时间
			var date = new Date;
			var today = timeFormat(date);
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-趋势分析'+today;
   			var result = ret.result;//返回数据集
   			var tubiaoDate=ret.loadTable;//图表一数据
   			var stadubiao = ret.stadubiao;
   			var endtubiao = ret.endtubiao;
   			var siteN = ret.siteN;
			var titContext="数据说明：新老客户对比"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称：新顾客数（人）&老顾客数（人）";
			var biaogeshuoming = "数据说明：新老客户对比"+"<br/>"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称：新顾客数（人）&老顾客数（人）";
					
			$("#biaogeshuoming").html(biaogeshuoming);
   			var resultXY=getXY(result);
			xsisRe=resultXY[0];
			
			dataRe=resultXY[1];	   
			dataRe1=resultXY[2];	  		
   			
			xsis = xsisRe.split(",");
			var titName = "['新顾客数','老顾客数']";
   			titName= eval(titName);

			/**
   			 * 横坐标只有一个值时显示为柱状图，柱状宽度最大为40
   			 */
   			var lineType = 'line';
   			if(xsis.length ==1){
   				lineType = 'bar';
   			}else{
   				lineType = 'line';
   			}
			//获取当前时间
			var date = new Date;
			var today =  timeFormat(date);
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-趋势分析'+today;
   			var barMaxWidthn = 40;
   			var markLinePrecision = 0;
   			data = eval("[{name:'新顾客数',type:lineType,smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{ color:'#feab41',label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe + "]},{name:'老顾客数',type:lineType,smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{ color:'#00BFFF',label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe1 + "]}]");	

   			var  option = {
			title : {
 		      text: titContext,
 		      y:'bottom',
 		      x:titleOffens,
 		      textStyle:{
 		       	fontSize: 12,
   		        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
   		        fontWeight:'normal'
 		    	}		
 		    },
 		   tooltip: {
   				trigger: 'axis',
   			},
			legend: {
				data:titName,
				y:legendY
				},
			dataZoom: {
   		        show: true,
   		        y:dataZoomY 
   		    },
			grid:{
   				x:'7.6%',
				x2:'7.6%',
   				y:'11%',
   				y2:'27%',
   				borderWidth: gridBorderWidth,
				borderColor:'#EEE'
   			},
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            magicType : {show: true, type: [ 'stack']},
		            restore : {show: true},
		            saveAsImage : {show: true,name:toolboxName}
		        },
				x:toolboxX,
				y:toolboxY
		    },
		    calculable : true,
		    xAxis : [
		        {
		        	name : '（日）',
		        	boundaryGap: true,//两端空白策略
		        	allowDecimals :true,//使用小数
		            type : 'category',
		            splitLine: {show: xAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		            splitArea:{
						show:xAxissplitArea,
						areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
					},
		            data : xsis,
		            axisTick:{
						show:true,
						interval:0
					}
		        }
		    ],
		    yAxis : [
		        {
					axisLabel:{
							formatter: function (value) {
			            		if(value > 10000){
			            			return (value/10000)+'万';
			            		}else{
			            			return value + '';
			            		}
							}
						},
		        	splitLine: {
						show: yAxisSplitLine,
						lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		        	splitArea:{
						show:yAxissplitArea,
						areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
					},
		        	name : '（人次）',
		            type : 'value'
		        }
		    ],
		    series : data
		};
   			//改变窗口大小使图标自适应窗口显示
   			window.onresize = function () {
   				myChart.resize();
   			}
   			//加载折线图
   			myChart.setOption(option);
   			//加载表格
   			loadChartTable(tubiaoDate);
   			hideLoading();
			
			var peiNweOld = ret.peiNweOld;
			loadpeiNweOldGraph(peiNweOld,stadubiao,endtubiao,siteN);
			
			var phoneTerminal = ret.phoneTerminal;
			loadpeiTerminalGraph(phoneTerminal,stadubiao,endtubiao,siteN);
			
			var comeFreq = ret.comeFreq;
			loadpeiComeFreqGraph(comeFreq,stadubiao,endtubiao,siteN);
			
			var retentionavg = ret.retentionavg;
			loadpeiRetentionTimeGraph(retentionavg,stadubiao,endtubiao,siteN);
			
			var retReportGraphData = ret.retReportGraphData;
			loadReportGraphDataChart(retReportGraphData,stadubiao,endtubiao,siteN);
			
			
   		},
		error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
   	})
}

//
function getStartEndComeXY(result){
	var xsisRe="";
	var dataRe="";
	var dataRe1="";
	for(var i=0;i<result.length;i++){
		xsisRe = xsisRe + result[i].time+",";
		indexNamefiled = "innum";
		dataRe = dataRe+((getObjectVlue(result[i],indexNamefiled))==null?0:(getObjectVlue(result[i],indexNamefiled)))+",";
		indexNamefiled1 = "outnum";
		dataRe1 = dataRe1+((getObjectVlue(result[i],indexNamefiled1))==null?0:(getObjectVlue(result[i],indexNamefiled1)))+",";
	}
	xsisRe=xsisRe.substring(0,xsisRe.length-1);
	dataRe=dataRe.substring(0,dataRe.length-1);
	dataRe1=dataRe1.substring(0,dataRe1.length-1);
	var result =new Array();
	result.push(xsisRe);
	result.push(dataRe);
	result.push(dataRe1);
	return result
}

//加载折线图表
 function loadReportGraphDataChart(retReportGraphData,stadubiao,endtubiao,siteN) {
     var data = [];
     var xsis = [];
     var myChart = echarts.init(document.getElementById("historyWeatherGraph"));
   			var width = $("#historyWeatherGraph").width();
			var height = $("#historyWeatherGraph").height();
			var titleOffens = width*7.6/100;
			var dataZoomY = height*(1-19/100);
			var toolboxX = width*80/100;
			var legendY = height*4/100;
			var toolboxY = height*4/100;
			//获取当前时间
			var date = new Date;
			var today = timeFormat(date);
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-顾客首末到店时间分析'+today;
			var titContext="数据说明：顾客首末到店时间分析"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称：首次到达人数&最末离开人数";
   			var resultXY=getStartEndComeXY(retReportGraphData);
			xsisRe=resultXY[0];
			dataRe=resultXY[1];	   
			dataRe1=resultXY[2];	  		
			xsis = xsisRe.split(",");
			var titName = "['首次到达人数','最末离开人数']";
   			titName= eval(titName);

			/**
   			 * 横坐标只有一个值时显示为柱状图，柱状宽度最大为40
   			 */
   			var lineType = 'bar';
//   			if(xsis.length ==1){
//   				lineType = 'bar';
//   			}else{
//   				lineType = 'line';
//   			}
			//获取当前时间
			var date = new Date;
			var today =  timeFormat(date);
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-顾客首末到店时间分析'+today;
   			var barMaxWidthn = 40;
   			var markLinePrecision = 0;
   			data = eval("[{name:'首次到达人数',type:lineType,stack: '总量',smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{ areaStyle: {type: 'default'},color:'#feab41',label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe + "]},{name:'最末离开人数',type:lineType,stack: '总量',smooth: smoothType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{ areaStyle: {type: 'default'},color:'#00BFFF',label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataRe1 + "]}]");	

   			var  option = {
			title : {
 		      text: titContext,
 		      y:'bottom',
 		      x:titleOffens,
 		      textStyle:{
 		       	fontSize: 12,
   		        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
   		        fontWeight:'normal'
 		    	}		
 		    },
 		   tooltip: {
   				trigger: 'axis',
   			},
			legend: {
				data:titName,
				y:legendY
				},
			dataZoom: {
   		        show: true,
   		        y:dataZoomY 
   		    },
			grid:{
   				x:'7.6%',
				x2:'7.6%',
   				y:'11%',
   				y2:'27%',
   				borderWidth: gridBorderWidth,
				borderColor:'#EEE'
   			},
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            magicType : {show: true, type: [ 'stack']},
		            restore : {show: true},
		            saveAsImage : {show: true,name:toolboxName}
		        },
				x:toolboxX,
				y:toolboxY
		    },
		    calculable : true,
		    xAxis : [
		        {
		        	name : '（时）',
		        	boundaryGap: true,//两端空白策略
		        	allowDecimals :true,//使用小数
		            type : 'category',
		            splitLine: {show: xAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		            splitArea:{
						show:xAxissplitArea,
						areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
					},
		            data : xsis,
		            axisTick:{
						show:true,
						interval:0
					}
		        }
		    ],
		    yAxis : [
		        {
					axisLabel:{
							formatter: function (value) {
			            		if(value > 10000){
			            			return (value/10000)+'万';
			            		}else{
			            			return value + '';
			            		}
							}
						},
		        	splitLine: {
						show: yAxisSplitLine,
						lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		        	splitArea:{
						show:yAxissplitArea,
						areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
					},
		        	name : '（人次）',
		            type : 'value'
		        }
		    ],
		    series : data
		};
   			//改变窗口大小使图标自适应窗口显示
   			window.onresize = function () {
   				myChart.resize();
   			}
   			//加载折线图
   			myChart.setOption(option);
}


function getWeek(dateStr){
	 arys1=dateStr.split('-'); 
	 var ssdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2]);   
	 if(ssdate.getDay()==0){
		 return "星期天"
	 }else if(ssdate.getDay()==1){
		 return "星期一"
	 }else if(ssdate.getDay()==2){
		 return "星期二"
	 }else if(ssdate.getDay()==3){
		 return "星期三"
	 }else if(ssdate.getDay()==4){
		 return "星期四"
	 }else if(ssdate.getDay()==5){
		 return "星期五"
	 }else if(ssdate.getDay()==6){
		 return "星期六" 
	 }
}

function loadChartTable(tubiaoDate){
	$("#hdtable").val(tubiaoDate);
	showtable(1);
}

function loadpeiNweOldGraph(peiNweOld,stadubiao,endtubiao,siteN){
	
	var newCustomerNum = peiNweOld.newCustomerNum;
	var oldCustomer = peiNweOld.oldCustomer;
	
	var total = newCustomerNum+oldCustomer;
	var tolalper = (parseFloat((newCustomerNum/total*100).toFixed(2))+parseFloat((oldCustomer/total*100).toFixed(2)));
	var totaldis = parseFloat(tolalper) - 100; 
	
	var width = $("#peiNweOld").width();
	var height = $("#peiNweOld").height();
	titContext = "新老顾客占比";
	var fontwithd = 18*6;
	var fontheight = 18;
	var titleX = (width - fontwithd)/2;
	var titleY = (height - fontheight)/2;
	var myChart = echarts.init(document.getElementById("peiNweOld"));
	var option = {
			title : {
		      text: titContext,
		      y:titleY,
		      x:titleX,
		      textStyle:{
		        fontSize: 18,
			        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
			        fontWeight:'normal'
		    	}		
			},
		    tooltip: {
				trigger: 'item',
				formatter: function(params, ticket, callback){
					console.log(params);
					var b = params[1];
					var c = params[2];
					var d =	params[3];
					var f = params[7];
					if(f==1){
						d = (parseFloat(d) - totaldis).toFixed(2);
					}
					return b+":"+c+"("+d+"%)";
				}
			},
			legend: {
		        orient : 'horizontal',
		        x : 'center',
				y : 'bottom',
		        data:['新顾客数','老顾客数']
    		},
	    	calculable : false,
		    series : [
		        {
		            type:'pie',
		            radius : ['50%', '70%'],
		            center: ['50%', '50%'],
					itemStyle : {
		                  normal : {
		                      label : {
		                          show : true
		                      },
		                      labelLine : {
		                          show : true
		                      }
		                  },
		              },
		            data:[
			                {value:newCustomerNum, name:'新顾客数'},
			                {value:oldCustomer, name:'老顾客数'}
			            ]
		        }
		    ]
	};
	//改变窗口大小使图标自适应窗口显示
	window.onresize = function () {
	myChart.resize();
	}
	myChart.setOption(option);
 }
 
 
function loadpeiTerminalGraph(pieData,stadubiao,endtubiao,siteN){
	
	var iphone = pieData.iphone;
	var samsung = pieData.samsung;
	var huawei = pieData.huawei;
	var xiaomi = pieData.xiaomi;
	var others = pieData.others;
	var unknown = pieData.unknown;
	
	var total = iphone+samsung+huawei+xiaomi+others+unknown;
	var tolalper = (parseFloat((iphone/total*100).toFixed(2))+parseFloat((samsung/total*100).toFixed(2))+parseFloat((huawei/total*100).toFixed(2))+
	parseFloat((xiaomi/total*100).toFixed(2))+parseFloat((others/total*100).toFixed(2))+parseFloat((unknown/total*100).toFixed(2)));
	var totaldis = parseFloat(tolalper) - 100; 
	
	var width = $("#peiTerminal").width();
	var height = $("#peiTerminal").height();
	titContext = "终端品牌占比";
	var fontwithd = 18*6;
	var fontheight = 18;
	var titleX = (width - fontwithd)/2;
	var titleY = (height - fontheight)/2;
	var myChart = echarts.init(document.getElementById("peiTerminal"));
	var option = {
			title : {
		      text: titContext,
		      y:titleY,
		      x:titleX,
		      textStyle:{
		        fontSize: 18,
			        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
			        fontWeight:'normal'
		    	}		
			},
		    tooltip: {
				trigger: 'item',
				formatter: function(params, ticket, callback){
					console.log(params);
					var b = params[1];
					var c = params[2];
					var d =	params[3];
					var f = params[7];
					if(f==1){
						d = (parseFloat(d) - totaldis).toFixed(2);
					}
					return b+":"+c+"("+d+"%)";
				}
			},
			legend: {
		        orient : 'horizontal',
		        x : 'center',
				y : 'bottom',
		        data:['苹果','三星','华为','小米','其他','未知']
    		},
	    	calculable : false,
		    series : [
		        {
		            type:'pie',
		            radius : ['50%', '70%'],
		            center: ['50%', '50%'],
					itemStyle : {
		                  normal : {
		                      label : {
		                          show : true
		                      },
		                      labelLine : {
		                          show : true
		                      }
		                  },
		              },
		            data:[
			                {value:iphone, name:'苹果'},
			                {value:samsung, name:'三星'},
			                {value:huawei, name:'华为'},
			                {value:xiaomi, name:'小米'},
			                {value:others, name:'其他'},
							{value:unknown, name:'未知'}
			            ]
		        }
		    ]
	};
	//改变窗口大小使图标自适应窗口显示
	window.onresize = function () {
	myChart.resize();
	}
	myChart.setOption(option);
 } 
 
 function loadpeiComeFreqGraph(pieData,stadubiao,endtubiao,siteN){
 	
	var one = pieData.one;
	var twoToFive = pieData.twoToFive;
	var fiveToTen = pieData.fiveToTen;
	
	var tenToFifteen = pieData.tenToFifteen;
	var FifteenToTwentyone = pieData.FifteenToTwentyone;
	var tenToTwentyone = tenToFifteen+FifteenToTwentyone;
	
	var twentyoneTotwentyEight = pieData.twentyoneTotwentyEight;
	var twentyEightTothirtyone = pieData.twentyEightTothirtyone;
	var twentyUp = twentyoneTotwentyEight + twentyEightTothirtyone;
	
	
	var total = one+twoToFive+fiveToTen+tenToTwentyone+twentyUp;
	var tolalper = (parseFloat((one/total*100).toFixed(2))+parseFloat((twoToFive/total*100).toFixed(2))+parseFloat((fiveToTen/total*100).toFixed(2))+
	parseFloat((tenToTwentyone/total*100).toFixed(2))+parseFloat((twentyUp/total*100).toFixed(2)));
	var totaldis = parseFloat(tolalper) - 100; 
	
	
	var width = $("#peiComeFreq").width();
	var height = $("#peiComeFreq").height();
	titContext = "到店频率占比";
	var fontwithd = 18*6;
	var fontheight = 18;
	var titleX = (width - fontwithd)/2;
	var titleY = (height - fontheight)/2;
	var myChart = echarts.init(document.getElementById("peiComeFreq"));
	var option = {
			title : {
		      text: titContext,
		      y:titleY,
		      x:titleX,
		      textStyle:{
		        fontSize: 18,
			        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
			        fontWeight:'normal'
		    	}		
			},
		    tooltip: {
				trigger: 'item',
				formatter: function(params, ticket, callback){
					console.log(params);
					var b = params[1];
					var c = params[2];
					var d =	params[3];
					var f = params[7];
					if(f==1){
						d = (parseFloat(d) - totaldis).toFixed(2);
					}
					return b+":"+c+"("+d+"%)";
				}
			},
			legend: {
		        orient : 'horizontal',
		        x : 'center',
				y : 'bottom',
		        data:['1次','2-5次','5-10次','10-20次','20次以上']
    		},
	    	calculable : false,
		    series : [
		        {
		            type:'pie',
		            radius : ['50%', '70%'],
		            center: ['50%', '50%'],
					itemStyle : {
		                  normal : {
		                      label : {
		                          show : true
		                      },
		                      labelLine : {
		                          show : true
		                      }
		                  },
		              },
		            data:[
			                {value:one, name:'1次'},
			                {value:twoToFive, name:'2-5次'},
			                {value:fiveToTen, name:'5-10次'},
			                {value:tenToTwentyone, name:'10-20次'},
							{value:twentyUp, name:'20次以上'}
			            ]
		        }
		    ]
	};
	//改变窗口大小使图标自适应窗口显示
	window.onresize = function () {
	myChart.resize();
	}
	myChart.setOption(option);
 } 
 
  function loadpeiRetentionTimeGraph(pieData,stadubiao,endtubiao,siteN){
  	var totaldis = 0;
	var siteyype = pieData.siteyype;
	var data ="";
	if(siteyype == 600){
		var storeZoreTwo = pieData.storeZoreTwo;
		var storeTwoFive = pieData.storeTwoFive;
		var storeFiveTen = pieData.storeFiveTen;
		var storeTenThirty = pieData.storeTenThirty;
		var storeThirtySixty = pieData.storeThirtySixty;
		var storeSixtyOneHtwenty = pieData.storeSixtyOneHtwenty;
		var OnehundredtwentyUp = pieData.OnehundredtwentyUp;
		data = "{value:"+storeZoreTwo+", name:'2分钟以下'},{value:"+storeTwoFive+", name:'2-5分钟'},"+
		"{value:"+storeFiveTen+", name:'5-10分钟'},{value:"+storeTenThirty+", name:'10-30分钟'},{value:"+storeThirtySixty+", name:'30-60分钟'},"+
		"{value:"+storeSixtyOneHtwenty+", name:'60-120分钟'},{value:"+OnehundredtwentyUp+", name:'120分钟以上'},";
		var total = storeZoreTwo+storeTwoFive+storeFiveTen+storeTenThirty+storeThirtySixty+
		storeSixtyOneHtwenty+OnehundredtwentyUp;
		var tolalper = (parseFloat((storeZoreTwo/total*100).toFixed(2))+parseFloat((storeTwoFive/total*100).toFixed(2))+
		parseFloat((storeFiveTen/total*100).toFixed(2))+parseFloat((storeTenThirty/total*100).toFixed(2))+parseFloat((storeThirtySixty/total*100).toFixed(2))+
		parseFloat((storeSixtyOneHtwenty/total*100).toFixed(2))+parseFloat((OnehundredtwentyUp/total*100).toFixed(2)));
		totaldis = parseFloat(tolalper) - 100; 
		
	}else if(siteyype == 300){
		var squareZoreTen = pieData.squareZoreTen;
		var squareTenThirty = pieData.squareTenThirty;
		var squareThirtySixty = pieData.squareThirtySixty;
		var squareSixtyOneHtwenty = pieData.squareSixtyOneHtwenty;
		var squareOneHtwentyToOneHEight = pieData.squareOneHtwentyToOneHEight;
		var squareOneHeightToTwoHfourty = pieData.squareOneHeightToTwoHfourty;
		var squareTwoHfourtyUp = pieData.squareTwoHfourtyUp;
		data = "{value:"+squareZoreTen+", name:'10分钟以下'},{value:"+squareTenThirty+", name:'10-30分钟'},{value:"+squareThirtySixty+", name:'30-60分钟'},"+
		"{value:"+squareSixtyOneHtwenty+", name:'60-120分钟'},{value:"+squareOneHtwentyToOneHEight+", name:'120-180分钟'},{value:"+squareOneHeightToTwoHfourty+", name:'180-240分钟'},"
		+"{value:"+squareTwoHfourtyUp+", name:'240分钟以上'},";
		var total = squareZoreTen+squareTenThirty+squareThirtySixty+squareSixtyOneHtwenty+squareOneHtwentyToOneHEight+squareOneHeightToTwoHfourty+squareTwoHfourtyUp;
		var tolalper = (parseFloat((squareZoreTen/total*100).toFixed(2))+parseFloat((squareTenThirty/total*100).toFixed(2))+parseFloat((squareThirtySixty/total*100).toFixed(2))+parseFloat((squareSixtyOneHtwenty/total*100).toFixed(2))+parseFloat((squareOneHtwentyToOneHEight/total*100).toFixed(2))+parseFloat((squareOneHeightToTwoHfourty/total*100).toFixed(2))+parseFloat((squareTwoHfourtyUp/total*100).toFixed(2)));
		totaldis = parseFloat(tolalper) - 100; 
		
	}else{
		data = "";
	}
  	data = eval("["+data+"]");
	
	var width = $("#peiRetentionTime").width();
	var height = $("#peiRetentionTime").height();
	titContext = "滞留时间占比";
	var fontwithd = 18*6;
	var fontheight = 18;
	var titleX = (width - fontwithd)/2;
	var titleY = (height - fontheight)/2;
	var myChart = echarts.init(document.getElementById("peiRetentionTime"));
	var option = {
			title : {
		      text: titContext,
		      y:titleY,
		      x:titleX,
		      textStyle:{
		        fontSize: 18,
			        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
			        fontWeight:'normal'
		    	}		
			},
		    tooltip: {
				trigger: 'item',
				formatter: function(params, ticket, callback){
					console.log(params);
					var b = params[1];
					var c = params[2];
					var d =	params[3];
					var f = params[7];
					if(f==1){
						d = (parseFloat(d) - totaldis).toFixed(2);
					}
					return b+":"+c+"("+d+"%)";
				}
			},
			legend: {
		        orient : 'horizontal',
		        x : 'center',
				y : 'bottom',
		        data:['10分钟以下','10-30分钟','30-60分钟','60-120分钟','120-180分钟','180-240分钟','240分钟以上']
    		},
	    	calculable : false,
		    series : [
		        {
		            type:'pie',
		            radius : ['50%', '70%'],
		            center: ['50%', '50%'],
					itemStyle : {
		                  normal : {
		                      label : {
		                          show : true
		                      },
		                      labelLine : {
		                          show : true
		                      }
		                  },
		              },
		            data:data
		        }
		    ]
	};
	//改变窗口大小使图标自适应窗口显示
	window.onresize = function () {
	myChart.resize();
	}
	myChart.setOption(option);
 } 
